<?php

namespace App\Observers;

use App\Models\User;
use App\Models\Group;
use App\Repositories\GroupRepository;

class UserObserver
{
    /**
     * @param User $user
     */
    public function created(User $user)
    {
        /** @var GroupRepository $groupRepository */
        $groupRepository = resolve(GroupRepository::class);
        $groups = Group::where('is_official', true)->get();
        $groups->each(function ($group) use ($groupRepository, $user) {
            $groupRepository->addUser($group, $user);
        });
    }
}
